﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.IO;

namespace PasswordControl
{
    public class ProfileData
    {
        static private List<ProfileData> m_profileList = new List<ProfileData>();
        static public List<ProfileData> ProfileList
        {
            get { return m_profileList; }
            private set { m_profileList = value; }
        }

        // data file path
        static private readonly string PATH = ControlProgram.DATA_FILE;

        // profile name
        public string ProfileName { get; set; }

        // checkbox display and contain in the main form. checked or not
        private bool m_displayData = true;
        public bool DisplayData 
        { 
            get { return m_displayData; } 
            set { m_displayData = value; } 
        }
        private bool m_searchContain = true;
        public bool SearchContain
        {
            get { return m_searchContain; }
            set { m_searchContain = value; }
        }

        //constructors
        public ProfileData(string name)
        {
            ProfileName = name;
        }
        public ProfileData() { }

        // find
        static public ProfileData FindProfileData(string name)
        {
            foreach (ProfileData temp in ProfileList)
            {
                if (temp.ProfileName == name)
                    return temp;
            }
            return null;
        }

        // add
        static public ProfileData ProfileDataAdd(string name)
        {
            ProfileData new_profile = new ProfileData(name);

            ProfileList.Add(new_profile);

            return new_profile;
        }

        // save data
        static public void SaveProfileData()
        {
            DataSerialize.SaveData<List<ProfileData>>(ProfileList, PATH);
        }
        // load data 
        static public void LoadProfileData()
        {
            if (!File.Exists(PATH))
                return;

            ProfileList = DataSerialize.LoadData<List<ProfileData>>(PATH);
        }
    }
}
